import React, {Component} from 'react';
import {Form, Radio, Switch, Button, Icon, Select} from "antd";
import Chooser from "components/chooser";
import constants from "share/constants"
import {messages} from "share/common";

const FormItem = Form.Item;
const RadioGroup = Radio.Group;
const Option = Select.Option;

@Form.create()
class SetExpenseType extends Component {

  render() {
    const { getFieldDecorator, getFieldValue } = this.props.form;
    const { ruleInfo, record, disabled } = this.props;
    return (
      <div>
        <Form className='new-form'>
          <FormItem label={messages('expense-14.key561')/*启用状态*/}>
            {getFieldDecorator('enabled', {
              valuePropName: 'checked',
              initialValue: record.expReceiptMappingItemId ? record.enabled : true
            })(
              <Switch disabled={disabled}/>
            )}
          </FormItem>
          <FormItem label={messages('expense-14.key562')/*设置方式*/}>
            {getFieldDecorator('expTypeSettingMode', {
              initialValue: record.expTypeSettingMode || 'TYPE'
            })(
              <RadioGroup disabled={disabled}>
                <Radio value="TYPE">{messages('common.expense.type')/*费用类型*/}</Radio>
                <Radio value="ATTRIBUTE">{messages('expense-14.key563')/*费用属性*/}</Radio>
              </RadioGroup>
            )}
          </FormItem>
          {getFieldValue('expTypeSettingMode') === 'TYPE' && (
            <FormItem label={messages('common.expense.type')/*费用类型*/}>
              {getFieldDecorator('expTypeList', {
                rules: [{
                  required: true,
                  message: messages('common.select')/*请选择*/
                }],
                initialValue: record.expTypeList
              })(
                <Chooser
                  type="selectInvoiceType"
                  labelKey="name"
                  valueKey="id"
                  disabled={disabled}
                  listExtraParams={{
                    levelCode: ruleInfo.levelCode,
                    setOfBooksId: ruleInfo.levelCode === 'TENANT' ? undefined : ruleInfo.levelOrgId,
                    pasteInvoiceNeeded: true,
                    enabled: true
                  }}
                />
              )}
            </FormItem>
          )}
          {getFieldValue('expTypeSettingMode') === 'ATTRIBUTE' && (
            <FormItem label={messages('expense-14.key563')/*费用属性*/}>
              {getFieldDecorator('expAttribute', {
                rules: [{
                  required: true,
                  message: messages('common.select')/*请选择*/
                }],
                initialValue: record.expAttribute
              })(
                <Select placeholder={messages('common.select')/*请选择*/} disabled={disabled}>
                  {constants.expenseAttrs.map(item => <Option key={item.value}>{item.name}</Option>)}
                </Select>
              )}
            </FormItem>
          )}
        </Form>
      </div>
    );
  }
}

export default SetExpenseType;
